﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace VideoChatClient
{
	//
	// If you want your Action to target elements other than its parent, extend your class
	// from TargetedTriggerAction instead of from TriggerAction
	//
	public class WindowClosingAction : TriggerAction<Window>
	{
		public WindowClosingAction()
		{
			// Insert code required on object creation below this point.
		}

		protected override void Invoke(object o)
		{
            AssociatedObject.Closing += (_1, _2) => 
            {
                App.ViewModel.IsMediaSending = false;
                if (App.ViewModel.Participant == null) return;
                App.ViewModel.Participant.Leave(App.ViewModel.UserName); 
            };
		}
	}
}